/**
 *	\file AKCPPConvertors.mm
 *  
 *  \section desc_sec Description
 *  Description
 *  
 *  \if copyright
 *  	Copyright 2008 Ben Chen. All rights reserved.
 *  \endif
 *  
 *  \section hist_sec Change History:
 *  	-	2/20/08		BC		Created this file
 *  
 *  <hr>
 *  \addtogroup AnimalKingdom
 *  @{
 */

#import "AKCPPConvertors.h"
using namespace std;

NSArray *AKPieceArrayFromVector (const vector<AKPiece> *piecesVec) {
	NSArray *retVal = nil;	
	if (piecesVec && piecesVec->size()) {
		NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:piecesVec->size()];
		for (int i = 0; i < piecesVec->size(); ++i) {
			AKPiece piece = (*piecesVec)[i];
			NSValue *pieceValue = [NSValue value:&piece withObjCType:@encode(AKPiece)];
			[tempArray addObject:pieceValue];		
		}
		retVal = [[tempArray copy] autorelease];
	}
	return retVal;
}

NSArray *AKMoveArrayFromVector (const vector<AKMove> *movesVec) {
	NSArray *retVal = nil;
	if (movesVec && movesVec->size()) {
		NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:movesVec->size()];
		for (int i = 0; i < movesVec->size(); ++i) {
			AKMove move = (*movesVec)[i];
			NSValue *moveValue = [NSValue value:&move withObjCType:@encode(AKMove)];
			[tempArray addObject:moveValue];
		}
		retVal = [[tempArray copy] autorelease];
	}
	return retVal;
}

NSArray *AKSideIndexArrayFromVector (const vector<AKSideIndex> *sideIndicesVec) {
	NSArray *retVal = nil;
	if (sideIndicesVec && sideIndicesVec->size()) {
		NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:sideIndicesVec->size()];
		for (int i = 0; i < sideIndicesVec->size(); ++i) {
			AKSideIndex sideIndex = (*sideIndicesVec)[i];
			NSNumber *sideData = [NSNumber numberWithInt:sideIndex];
			[tempArray addObject:sideData];
		}
		retVal = [[tempArray copy] autorelease];
	}
	return retVal;	
}

NSArray *AKCellIndexArrayFromVector (const vector<AKCellIndex> *cellIndicesVec) {
	NSArray *retVal = nil;
	if (cellIndicesVec && cellIndicesVec->size()) {
		NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:cellIndicesVec->size()];
		for (int i = 0; i < cellIndicesVec->size(); ++i) {
			AKCellIndex cellIndex = (*cellIndicesVec)[i];
			NSNumber *cellIndexData = [NSNumber numberWithInt:cellIndex];
			[tempArray addObject:cellIndexData];
		}
		retVal = [[tempArray copy] autorelease];
	}
	return retVal;		
}

/** @} */
